package ca.abubakrsagar.breadboardsim;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * This is the main class of the project. It deals with handling the main window of program and manages its components. 
 * @author Abubakr, Sagar
 * @since May 15, 2012
 * 
 * 
 */
public class Main {

	private JFrame mainWindow = new JFrame("Bread Board Simulator");		//makes a new frame and calls it Bread Board Simulator
	private JPanel mainPanel = new JPanel();								//makes a new panel that will hold everything
	private JPanel leftPanel = new JPanel(); //A panel to be placed on the left side of the window.
	
	
	
	
	private BreadboardPanel breadboardPanel = new BreadboardPanel(); //The breadboard panel.
	private PropertiesPanel propertiesPanel = new PropertiesPanel(breadboardPanel); //The properties Panel.
	
	private ComponentsPanel componentsPanel = new ComponentsPanel(breadboardPanel);	//makes an object of the ComponentsPanel
	private MenuBar menuBar = new MenuBar(breadboardPanel);								//makes a new menubar that will contain multiple options
	public Main() {
		setupMainWindow();
		breadboardPanel.setPropertiesPanel(propertiesPanel);	//sets the properties panel
	}

	/**
	 * Sets up the main window to display all data to the user in an organized
	 * manner.
	 */
	private void setupMainWindow() {

		
		mainWindow.setSize(new Dimension(1002, 564));
		
		//Center the window.
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();	
		mainWindow.setLocation(											
				(int) (dim.getWidth() - mainWindow.getWidth()) / 2,
				(int) (dim.getHeight() - mainWindow.getHeight()) / 2);
		
		//Setup mainWindow and mainPanel to display as required.
		mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mainPanel.setPreferredSize(new Dimension(1002, 564));			
		mainWindow.setJMenuBar(menuBar);								
		mainWindow.setContentPane(mainPanel);	
		leftPanel.setPreferredSize(new Dimension(900/5,253));

		//Add required panels onto the main panel.
		mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS));
		leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
		mainPanel.add(leftPanel);
		leftPanel.add(componentsPanel);
		leftPanel.add(propertiesPanel);
		mainPanel.add(breadboardPanel);
		
		//Display all windows.			
		mainPanel.setVisible(true);											
		mainWindow.setVisible(true);
	}

	public static void main(String[] args) {
		new Main();
	}
}
